package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseCategory1;
import com.atguigu.gmall.product.entity.BaseCategory2;
import com.atguigu.gmall.product.entity.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
@Api(tags = "三级分类管理(后台管理系统)")
public class BaseCategoryController {

    @Autowired
    BaseCategory1Service baseCategory1Service;

    @Autowired
    BaseCategory2Service baseCategory2Service;

    @Autowired
    BaseCategory3Service baseCategory3Service;

    @ApiOperation("查询一级分类")
    @GetMapping("getCategory1")
    public Result getCategory1() {
        List<BaseCategory1> list = baseCategory1Service.list();
        return Result.ok(list);
    }

    @ApiOperation("根据一级分类id,查询二级分类")
    @GetMapping("getCategory2/{c1Id}")
    public Result getCategory2(@PathVariable(value = "c1Id") Long c1Id) {
        List<BaseCategory2> list = baseCategory2Service.getCategory2ByC1Id(c1Id);
        return Result.ok(list);
    }


    @ApiOperation("根据二级分类id,查询三级分类")
    @GetMapping("getCategory3/{c2Id}")
    public Result getCategory3(@PathVariable(value = "c2Id") Long c2Id) {
        List<BaseCategory3> list = baseCategory3Service.getCategory3ByC2Id(c2Id);
        return Result.ok(list);
    }


}
